home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libtext / marble.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.7 KB  |  71 lines

  1. /*
  2.  * marble.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * marble.c,v 4.1 1994/08/09 08:03:03 explorer Exp
  17.  *
  18.  * marble.c,v
  19.  * Revision 4.1  1994/08/09  08:03:03  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:15  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:43:06  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "texture.h"
  30. #include "marble.h"
  31.  
  32. MarbleText *
  33. MarbleCreate(mapname)
  34. char *mapname;
  35. {
  36.     MarbleText *marble;
  37.  
  38.     marble = (MarbleText *)Malloc(sizeof(MarbleText));
  39.     if (mapname)
  40.         marble->colormap = ColormapRead(mapname);
  41.     else
  42.         marble->colormap = (Color *)NULL;
  43.     return marble;
  44. }
  45.  
  46. void
  47. MarbleApply(marble, prim, ray, pos, norm, gnorm, surf)
  48. MarbleText *marble;
  49. Geom *prim;
  50. Ray *ray;
  51. Vector *pos, *norm, *gnorm;
  52. Surface *surf;
  53. {
  54.     Float val;
  55.     int index;
  56.  
  57.     val = Marble(pos);
  58.     if (marble->colormap) {
  59.         index = (int)(255. * val);
  60.         surf->diff.r *= marble->colormap[index].r;
  61.         surf->diff.g *= marble->colormap[index].g;
  62.         surf->diff.b *= marble->colormap[index].b;
  63.         surf->amb.r *= marble->colormap[index].r;
  64.         surf->amb.g *= marble->colormap[index].g;
  65.         surf->amb.b *= marble->colormap[index].b;
  66.     } else {
  67.         ColorScale(val, surf->amb, &surf->amb);
  68.         ColorScale(val, surf->diff, &surf->diff);
  69.     }
  70. }
  71.